package cn.edu.cdu.group4nb.service.impl;

import cn.edu.cdu.group4nb.mapper.AttendenceMapper;
import cn.edu.cdu.group4nb.po.Attendence;
import cn.edu.cdu.group4nb.service.AttendenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AttendenceServiceImpl implements AttendenceService {
    @Autowired
    private AttendenceMapper attendenceMapper;
    @Override
    public List<Map<String, Object>> selectAttend(String userid) {
        List<Map<String, Object>> timeList = attendenceMapper.selectAttend(userid);
        return timeList;
    }
    public List<Map<String, Object>> selectUserAttend(String userid) {
        List<Map<String, Object>> timeList = attendenceMapper.selectAttend(userid);
        return timeList;
    }

    public Boolean insertTime(int user_info_id){
        if(attendenceMapper.insertTime(user_info_id)==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean insertLeftTime(int user_info_id) {
        return null;
    }

    public List<Map<String, Object>> selectUser() {
        List<Map<String, Object>> userList = attendenceMapper.selectUser();
        return userList;
    }

    public Boolean selectInTime(int user_info_id){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String InTime=df.format(new Date());
        System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        Attendence attendence = attendenceMapper.selectInTime(user_info_id, InTime);
        attendenceMapper.updateTime(user_info_id,attendence.getAttendInTime());
        return true;
    }

    public Boolean ifTime(int user_info_id){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String InTime=df.format(new Date());
        System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        Attendence attendence = attendenceMapper.selectInTime(user_info_id, InTime);
        if(attendence==null){
            return true;
        }
        else {
            return false;
        }
    }

}
